/* eslint-disable */
// @ts-ignore
import { queryOptions, useMutation } from '@tanstack/vue-query';
import type { DefaultError } from '@tanstack/vue-query';
import request from '@/utils/request';
import { CustomRequestOptions } from '@/interceptors/request';

import * as apis from './productCategory';
import * as API from './types';

/** 分页查询产品类别 GET /product_category */
export function productCategoryGetCategoryPageQueryOptions(options: {
  // 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
  params: API.ProductCategoryGetCategoryPageParams;
  options?: CustomRequestOptions;
}) {
  return queryOptions({
    queryFn: async ({ queryKey }) => {
      return apis.productCategoryGetCategoryPage(queryKey[1] as typeof options);
    },
    queryKey: ['productCategoryGetCategoryPage', options],
  });
}

/** 编辑产品类别 PUT /product_category */
export function useProductCategoryEditCategoryMutation(options?: {
  onSuccess?: (value?: API.ResponseModelObject_) => void;
  onError?: (error?: DefaultError) => void;
}) {
  const { onSuccess, onError } = options || {};

  const response = useMutation({
    mutationFn: apis.productCategoryEditCategory,
    onSuccess(data: API.ResponseModelObject_) {
      onSuccess?.(data);
    },
    onError(error) {
      onError?.(error);
    },
  });

  return response;
}

/** 新增产品类别 POST /product_category */
export function useProductCategoryAddCategoryMutation(options?: {
  onSuccess?: (value?: API.ResponseModelObject_) => void;
  onError?: (error?: DefaultError) => void;
}) {
  const { onSuccess, onError } = options || {};

  const response = useMutation({
    mutationFn: apis.productCategoryAddCategory,
    onSuccess(data: API.ResponseModelObject_) {
      onSuccess?.(data);
    },
    onError(error) {
      onError?.(error);
    },
  });

  return response;
}

/** 删除产品类别 DELETE /product_category */
export function useProductCategoryDeleteCategoryMutation(options?: {
  onSuccess?: (value?: API.ResponseModelObject_) => void;
  onError?: (error?: DefaultError) => void;
}) {
  const { onSuccess, onError } = options || {};

  const response = useMutation({
    mutationFn: apis.productCategoryDeleteCategory,
    onSuccess(data: API.ResponseModelObject_) {
      onSuccess?.(data);
    },
    onError(error) {
      onError?.(error);
    },
  });

  return response;
}

/** 查询产品类别列表 GET /product_category/list */
export function productCategoryGetCategoryListQueryOptions(options: {
  options?: CustomRequestOptions;
}) {
  return queryOptions({
    queryFn: async ({ queryKey }) => {
      return apis.productCategoryGetCategoryList(queryKey[1] as typeof options);
    },
    queryKey: ['productCategoryGetCategoryList', options],
  });
}
